{% extends 'base.html' %}
<!--{% block css %}
        <style>
                .pat4{
                        background-color: #00BB00;
                }
        </style>
{% endblock %}-->

{% block body %}
        {% for item in data %}
        <a href="{{ item.url }}">{{ item.title }}</a><br />
        {{ item.summary }}<br />
        <!--点赞功能，点击则数字加1，页面不刷新，用ajax来实现;Favor()函数有两个参数，this表示点击的标签，item.id表示哪条新闻-->
        <a href="#" onclick="Favor(this,{{ item.id }});">good {{item.favor_count}}</a>
        <a href="#" onclick="Relay(this,{{ item.id }});">relay {{ item.replay_count }}</a>
        {{ item.create_date|date:"Y-m-d H:i:s" }}<br />
        <div has-input="0" class="part4 hide">
                <div class="replys"></div>
                <div class="input">
                        <label>回复内容：</label><textarea></textarea>
                        <input type="button" value="提交"/>
                </div>

        </div>
        {% endfor %}
{% endblock %}

{% block js %}
<script type="text/javascript">
$.ajaxSetup({
  data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
    function Favor(doc,id){
    console.log(doc)
        $.ajax({
            url: '/bbs/addfavor/',
            data: { nid:id },
            type: 'POST',
            success:function(callback){
                    console.log(callback)
                var obj = jQuery.parseJSON(callback);
                    console.log(obj.status)
                var temp = 'good'+ obj.data;
                $(doc).text(temp);

            }, //end  func
            error: function(XMLHttpRequest, textStatus, errorThrown){
                     console.info(XMLHttpRequest,textStatus,errorThrown)
                      this;
                 },
        }
        );
    }//end Favor
    function Relay(doc,id) {
            $("#replay").toggle();
            $.ajax({
                    url:'/bbs/addreplay',
                    data:{nid:id},
                    type:'GET',
                    success:function (callback) {
                            var obj = jQuery.parseJSON(callback);
                            $.each(obj,function (k,v) {
                                    //console.log(v.fields.content)
                                    temp = "<div>" + v.fields.content+"</div>";
                                    $(doc).parent().next().find('.reply').empty();
                                    console.log($(doc).parent())
                                    console.log($(doc).parent().next())
                                    $(doc).parent().next().find('.reply').append(temp);


                                    });//end each

                    }//end function
             });//end ajax
    } //end Relay
</script>
{% endblock %}
</html>